package com.community.common.pojo.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.Duration;
import java.time.LocalDateTime;

/**
 * <p>
 * 相机表
 * </p>
 *
 * @author superman
 * @since 2020-08-02
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@TableName("t_camera")
public class Camera implements Serializable {


    private static final long serialVersionUID = -6989515920543970456L;
    /**
     * 主键
     */
    private String id;

    /**
     * 相机唯一识别号sn
     */
    private String sn;
    /**
     * 局域网ip
     */
    private String ip;

    /**
     * 相机名
     */
    private String name;

    /**
     * 密码
     */
    private String password;

    /**
     * 关联小区ID
     */
    private String communityId;

    /**
     * 关联小区名称
     */
    private String communityName;

    /**
     * 门 -东门、西门
     */
    private String door;

    /**
     * 是否进口 0-进口 1-出口
     */
    private Integer whetherIn;

    /**
     * 是否在线 0-不在线 1-在线
     */
    @TableField(exist = false)
    private Integer online;

    public Integer getOnline() {
        if (heartTime == null) {
            return 0;
        }
        if (Duration.between(this.heartTime, LocalDateTime.now()).toMinutes() < 10) {
            return 1;
        }
        return 0;
    }

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime heartTime;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    /**
     * 修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;


}
